package com.thinkcube.edutainment.service.viewitem;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.thinkcube.edutainment.R;
import com.thinkcube.edutainment.domain.data.LessonContentData;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.lesson_content_detail_item)
public class LessonContntItem extends RelativeLayout {

	@ViewById(R.id.content_type_ic)
	ImageView imageView;

	@ViewById(R.id.content_title)
	TextView contentTitle;

	@ViewById(R.id.content_description)
	TextView contentDes;
	DisplayImageOptions options;
	ImageLoader imageLoader;

	@AfterViews
	void iniUi() {
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.icon)
				.showImageForEmptyUri(R.drawable.icon)
				.showImageOnFail(R.drawable.icon).cacheOnDisc(true)
				.displayer(new SimpleBitmapDisplayer())
				.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
				.bitmapConfig(Bitmap.Config.RGB_565).build(); // default;
		imageLoader = ImageLoader.getInstance();
	}

	public LessonContntItem(final Context context) {
		super(context);

	}

	public LessonContntItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public void bind(final LessonContentData lessonData) {

		contentTitle.setText(lessonData.getTitle());
		contentDes.setText(lessonData.getDescription());

		imageLoader.displayImage(lessonData.getIcon(), imageView, options);

	}
}
